
/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-11-01
 * Time:16:54
 */
public class TestDemo {
    //判断这个链表是否是回文
   public static Boolean chkPalindrome(MySingleList.MyList A) {
        // write code here
       //判断这个链表是否为空
       if(A == null){
           return false;
       }
       //判断这个链表是只有一个数字
       if(A.next==null){
           return true;
       }
       MySingleList.MyList slow = A;
       MySingleList.MyList fast = A;
       MySingleList.MyList curNext = null;
       MySingleList.MyList cur = null;

       while(fast != null || fast.next != null ){
           fast = fast.next.next;
           slow = slow.next;
       }

       while(curNext != null){

           curNext = cur.next;

           cur.next = slow;

           slow = slow.next;

           cur =curNext;

            if()
       }
    }
    /*
    现有一链表的头指针 ListNode* pHead，给一定值x，编写一段代码将所有小于x的结点排在其余结点之前，且不能改变原来的数据顺序，返回重新排列后的链表的头指针。
     */
    public static MySingleList.MyList partition(MySingleList.MyList pHead, int x){

        MySingleList.MyList bs=null;//头
        MySingleList.MyList be=null;//尾
        MySingleList.MyList as=null;//头
        MySingleList.MyList ae=null;//尾

        MySingleList.MyList cur=pHead;
        while(cur!=null){
            if(cur.val < x){
                if(bs==null){
                    bs=cur;
                    be=cur;
                }else{
                    be.next=cur;
                    be=be.next;
                }
            }else{
                if(as==null){
                    as=cur;
                    ae=cur;
                }else{
                    ae.next=cur;
                    ae=ae.next;
                }
            }
            cur=cur.next;
        }
//        //第二种的情况：大于的x的最后的一个元素是没有null,可能导致死循环
//        ae.next=null;--空指针异常
        //第一种情况：小于x没有
        if(bs==null){
            if(as!=null){
                ae.next=null;
                return as;
            }
        }
        be.next=as;
        ae.next=null;
        return bs;
    }
    public static MySingleList.MyList mergeTwoLists(MySingleList.MyList list1, MySingleList.MyList list2) {
        MySingleList.MyList newHead=new MySingleList.MyList(-1);
        MySingleList.MyList tmp=newHead;
        if(list1==null && list2==null){
            return null;
        }
        while(list1!=null&&list2!=null){
            if (list1.val>list2.val){
                tmp.next=list2;
                list2=list2.next;
                tmp=tmp.next;
            }else{
                tmp.next=list1;
                list1=list1.next;
                tmp=tmp.next;
            }
        }
        if(list1!=null){
            tmp.next=list1;
        }
        if(list2!=null){
            tmp.next=list2;
        }
        return newHead.next;

    }

    public static void main(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(15);
         mySingleList1.addLast(25);
        mySingleList1.addLast(56);
        mySingleList1.addLast(999);
        mySingleList1.display();
       MySingleList.MyList list=mySingleList1.reverseList(mySingleList1.head);
        //当成员变量和局部变量同名时，局部优先
        mySingleList1.display();
//        mySingleList1.reverseList();
//        mySingleList1.display();


//        MySingleList mySingleList2 = new MySingleList();
//        mySingleList2.addLast(12);
//        mySingleList2.addLast(23);
//        mySingleList2.addLast(34);
//
//        MySingleList.MyList newHead=mergeTwoLists(mySingleList1.head,mySingleList2.head);
//        mySingleList1.display(newHead);

    }
    public static void main1(String[] args) {
        MySingleList mySingleList=new MySingleList();
      //  mySingleList.Creation();
       // mySingleList.addFirst(32);
        mySingleList.addFirst(33);
        mySingleList.addFirst(33);
        mySingleList.addFirst(11);
        mySingleList.addFirst(33);
        mySingleList.addIndex(0,33);
        mySingleList.addIndex(5,33);
        mySingleList.addIndex(3,20);
        mySingleList.display();
       // mySingleList.remove(30);

      mySingleList.removeAllKey(33);
        mySingleList.display();
        mySingleList.clear();

        System.out.println(mySingleList.size());
        System.out.println(mySingleList.contains(9999));

    }
}
